package com.fsnbigdata.repository;
import io.springlets.data.jpa.repository.support.QueryDslRepositorySupportExt;
import org.springframework.roo.addon.layers.repository.jpa.annotations.RooJpaRepositoryCustomImpl;
import com.fsnbigdata.domain.VegetationDistribution;
import com.fsnbigdata.domain.QVegetationDistribution;
import com.fsnbigdata.domain.Vegetation;
import com.querydsl.core.types.Path;
import com.querydsl.jpa.JPQLQuery;
import io.springlets.data.domain.GlobalSearch;
import io.springlets.data.jpa.repository.support.QueryDslRepositorySupportExt.AttributeMappingBuilder;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

/**
 * = VegetationDistributionRepositoryImpl
 *
 * TODO Auto-generated class documentation
 *
 */
@RooJpaRepositoryCustomImpl(repository = VegetationDistributionRepositoryCustom.class)
@Transactional(readOnly = true)
public class VegetationDistributionRepositoryImpl extends QueryDslRepositorySupportExt<VegetationDistribution> implements VegetationDistributionRepositoryCustom {

    /**
     * TODO Auto-generated constructor documentation
     */
    VegetationDistributionRepositoryImpl() {
        super(VegetationDistribution.class);
    }

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String COUNTRY = "country";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String CITY = "city";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String PROVINCE = "province";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String DETAIL = "detail";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String STANDARD = "standard";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String VEGETATION = "vegetation";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String COUNTY = "county";

    /**
     * TODO Auto-generated method documentation
     *
     * @param vegetation
     * @param globalSearch
     * @param pageable
     * @return Page
     */
    public Page<VegetationDistribution> findByVegetation(Vegetation vegetation, GlobalSearch globalSearch, Pageable pageable) {
        QVegetationDistribution vegetationDistribution = QVegetationDistribution.vegetationDistribution;
        JPQLQuery<VegetationDistribution> query = from(vegetationDistribution);
        Assert.notNull(vegetation, "vegetation is required");
        query.where(vegetationDistribution.vegetation.eq(vegetation));
        Path<?>[] paths = new Path<?>[] { vegetationDistribution.vegetation, vegetationDistribution.standard, vegetationDistribution.country, vegetationDistribution.province, vegetationDistribution.city, vegetationDistribution.county, vegetationDistribution.detail };
        applyGlobalSearch(globalSearch, query, paths);
        AttributeMappingBuilder mapping = buildMapper().map(VEGETATION, vegetationDistribution.vegetation).map(STANDARD, vegetationDistribution.standard).map(COUNTRY, vegetationDistribution.country).map(PROVINCE, vegetationDistribution.province).map(CITY, vegetationDistribution.city).map(COUNTY, vegetationDistribution.county).map(DETAIL, vegetationDistribution.detail);
        applyPagination(pageable, query, mapping);
        applyOrderById(query);
        return loadPage(query, pageable, vegetationDistribution);
    }
}
